/**
 * Auto gen via dbpojo-gen.
 */
package com.us.usws.dao;

import java.util.List;

import net.iwsh.core.db.DBExecutor;
import net.iwsh.core.db.ext.DialectSyntaxParser;
import net.iwsh.core.db.ext.SQLWithParams;

import com.us.usws.model.domain.video.VideoAttendee;
import com.us.usws.model.flat.video.DOVideoAttendee;

/**
 * DAO class
 * @author robot
 */
public class VideoAttendeeDAO {

	/**
	 * Query SQLs
	 */
	private static final String SQL_GET_TOTAL_COUNT = "select count(*) from hv_video_attendee";

	private static final String SQL_GET_ALL_VIDEOATTENDEES = "select * from hv_video_attendee";

	private static final String SQL_GET_ATTENDEES_BY_VIDEO = "select * from hv_video_attendee where video_uid=?";

	/**
	 * CUR SQLs
	 */
	private static final String SQL_INSERT_VIDEOATTENDEE = "insert into hv_video_attendee(video_uid,user_uid,apply_date,is_approved,is_attended) values (?,?,?,?,?)";

	/**
	 * DBExeutor
	 */
	private DBExecutor dbe = new DBExecutor();

	/**
	 * Get Count.
	 */
	public int getTotalCount() {
		return dbe.getCount(SQL_GET_TOTAL_COUNT);
	}

	/**
	 * Get all list.
	 */
	public List<VideoAttendee> getAllVideoAttendees() {
		return dbe.list(SQL_GET_ALL_VIDEOATTENDEES, VideoAttendee.class);
	}

	/**
	 * Get all list by pagination.
	 */
	public List<VideoAttendee> getVideoAttendees(int start, int end) {
		SQLWithParams swp = DialectSyntaxParser.getParser().getPaginationSQLWithParams(SQL_GET_ALL_VIDEOATTENDEES, null, start, end);
		return dbe.list(swp.getSql(), VideoAttendee.class, swp.getParams());
	}

	/**
	 * get attendees by video
	 * @param videoUid
	 * @return
	 */
	public List<VideoAttendee> getAttendeesByVideo(String videoUid) {
		return dbe.list(SQL_GET_ATTENDEES_BY_VIDEO, VideoAttendee.class, videoUid);
	}

	/**
	 * Insert one row.
	 */
	public String insertVideoAttendee(DOVideoAttendee videoAttendee) {
		dbe.execute(SQL_INSERT_VIDEOATTENDEE, videoAttendee.getVideoUid(), videoAttendee.getUserUid(), videoAttendee.getApplyDate(),
				videoAttendee.getIsApproved(), videoAttendee.getIsAttended());
		return videoAttendee.getVideoUid();
	}

}